package zbg.cookiePage;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "LoginServlet",urlPatterns = "/loginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userName = request.getParameter("userName");
        String pwd = request.getParameter("pwd");
        if ("123".equals(userName)&&"123".equals(pwd)){
            Cookie cookie = new Cookie("userName", userName);
            response.addCookie(cookie);
            Cookie cookie1 = new Cookie("pwd", pwd);
            response.addCookie(cookie);
            response.addCookie(cookie1);
            response.sendRedirect("/servlet04/cookie.html");
        }else {
            response.setContentType("text/html; charset=UTF-8");
            response.getWriter().write("密码错误");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
